package com.wy.ssm01.service.impl;


import com.wy.ssm01.mapper.TestMapper;
import com.wy.ssm01.entity.MyTestEntity;
import com.wy.ssm01.service.TestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;

@Service("testServiceImpl")
public class TestServiceImpl implements TestService {


    @Autowired
    TestMapper testMapper;

    @Override
    public int insert(MyTestEntity testEntity) {
        return testMapper.insert(testEntity);
    }

    @Override
    public int delete(Integer testId) {
        return testMapper.delete(testId);
    }

    @Override
    public int update(MyTestEntity testEntity) {
        return testMapper.update(testEntity);
    }

    @Override
    public MyTestEntity queryById(Integer testId) {
        return testMapper.queryById(testId);
    }

    @Override
    public List<MyTestEntity> queryAll() {
        return testMapper.queryAll();
    }

    @Override
    public boolean transfer(Integer fromId, BigDecimal quantity, Integer toId) throws Exception {

        //查询数据库有没有这个人
        MyTestEntity person1 = testMapper.queryById(fromId);
        MyTestEntity person2 = testMapper.queryById(toId);
        if(person1==null){
            throw new Exception("转账人不存在");
        }
        if(person2 == null){
            throw new Exception("收帐人不存在");
        }


        /*
         * 转账额。。。。。。。。
         */
        boolean b = testMapper.sendMoney(quantity, toId);
        boolean b1 = testMapper.receiveMoney(quantity, fromId);

        int i = 1/0;
        try{


        }catch (Exception e){
            //保存异常信息


        }

      /*  try{
            //toId得到钱*/

            //fromId失去钱

           /* if (!b||!b1){
                throw new Exception("用户不存在");
            }*/

       /* }catch (Exception e){
            System.out.println("ddddddd");
            return false;
        }*/
        return true;
    }
}
